import 'package:flutter_app/bean/article_detail_entity.dart';
import 'package:flutter_app/manager/UserInfoManager.dart';
import 'package:flutter_app/network/Api.dart';
import 'package:flutter_app/network/ResultData.dart';
import 'package:flutter_app/utils/toast_utils.dart';
import 'package:flutter_app/widget/watermark/watermark_utils.dart';
import 'package:get/get.dart';

import 'news_detail_state.dart';

class NewsDetailLogic extends GetxController {
  final NewsDetailState state = NewsDetailState();

  late String id;

  @override
  void onInit() {
    super.onInit();
    id = Get.arguments;
  }

  @override
  void onReady() {
    super.onReady();
    WatermarkUtils().addWatermark(Get.context!, UserInfoManager().getUserName());

    postArticleDetail();
  }

  /// 门户-获取内容详情
  Future<void> postArticleDetail() async {
    Map<String, dynamic> param = {
      'id': id,
    };

    ResultData resultData = await Api.postArticleDetail(param);
    if (resultData.isSuccess) {
      state.articleDetailEntity = ArticleDetailEntity.fromJson(resultData.data['data']);
    } else {
      toast.show(resultData.data["message"]);
    }
    state.progressState = false;
    update();
  }

  @override
  void onClose() {
    super.onClose();
    WatermarkUtils().removeWatermark();
  }
}
